<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <!-- 自定义字段名为 title 的插槽 -->
      <template #status="{ record }">
            <!-- 对标题加上 tag -->
            <a-tag v-if="record.status == 1" color="blue">正常</a-tag>
            <a-tag v-if="record.status == 2" color="blue">禁用</a-tag>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import warehouseType from '@/api/warehouse/warehouseType'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  warehouseType.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  warehouseType.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_warehouse_type',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: warehouseType.getList,
  recycleApi: warehouseType.getRecycleList,
  add: {
    show: true,
    api: warehouseType.save,
    auth: ['warehouse:type:save']
  },
  edit: {
    show: true,
    api: warehouseType.update,
    auth: ['warehouse:type:update']
  },
  delete: {
    show: true,
    api: warehouseType.deletes,
    auth: ['warehouse:type:delete'],
    realApi: warehouseType.realDeletes,
    realAuth: ['warehouse:type:realDeletes']
  },
  recovery: {
    show: true,
    api: warehouseType.recoverys,
    auth: ['warehouse:type:recovery']
  },
  import: {
    show: true,
    url: 'warehouse/type/import',
    templateUrl: 'warehouse/type/downloadTemplate',
    auth: ['warehouse:type:import']
  },
  export: {
    show: true,
    url: 'warehouse/type/export',
    auth: ['warehouse:type:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "分类名称",
    dataIndex: "name",
    align: "center",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入分类名称"
    }
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "switch",
    align: "center",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    checkedValue: "1",
    uncheckedValue: "2"
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    align: "center",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建人",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新人",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'warehouse:type' } </script>